
from flask import Blueprint, render_template, redirect, url_for, flash, current_app
from flask_login import login_required, current_user
from fileshare.utils import redirect_back

main_bp = Blueprint('main', __name__)


@main_bp.route('/', methods=['GET'])
def index():
    if not current_app.config['SECURE_LINK'] and current_user.is_anonymous:
        return redirect(url_for('auth.login', key=''))
    return redirect(url_for('file.page'), code=302)


@main_bp.route('/<string:key>/', methods=['GET', 'POST'])
def login(key):
    return redirect(url_for('auth.login', key=key))


@main_bp.route('/index', methods=['GET'])
@login_required
def index_page():
    return render_template('index.html')
